package com.amado.springcloud.feignhystrix.client;

import com.amado.springcloud.user.vo.SNSResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("/fegin-user")
//项目名称
@FeignClient(name = "user-service",fallbackFactory = UserFeignFour.HystrixClientFallbackFactory.class)
public interface UserFeignFour {
    @DeleteMapping
    SNSResult<Void> deleteUser(@RequestParam("id") Long id);
    @Component
    class HystrixClientFallbackFactory implements FallbackFactory<UserFeignFour> {
        @Override
        public UserFeignFour create(Throwable cause) {
            return new UserFeignFour() {
                @Override
                public SNSResult<Void> deleteUser(Long id) {
                    return new SNSResult<>(SNSResult.StatusCode.ERROR);
                }
            };
        }
    }
}